<template>
  <div v-cloak style="padding:50px;">
    <h1 class="titleCenter">自定义时间转换指令</h1>
    <span>今天</span>
    <span v-timeNumber:w="timeNow"></span>
    <br>
    <br>
    <div v-timeNumber:yyyy-mm-dd="timeBefore"></div>
    <br>
    <br>

    <!-- 另一种方式:刚刚十分钟之前 -->
    <span>
      小王在
      <span v-time="aleayTime" style="font-weight:700;color:red"></span>发表了讲话
    </span>
  </div>
</template>

<script>
import directive from '../../common/js/directive'
export default {
  name: 'timeStamp',
  data () {
    return {
      timeNow: (new Date()).getTime(),
      timeBefore: 1488930695721, //2017-03-08
      aleayTime: 14889306957211
    }
  },
  created () {
    //this指向问题，箭头函数和普通函数指向不同
    function Timer (params) {
      this.id = 1;
      var _this = this;
      setTimeout(function () {
        //console.log(this) //undefined 使用时所在对象中并没有id
        //console.log(_this) //{id：1}

      }, 1000);

      setTimeout(() => {
        //console.log(this) //定义时所在对象
      }, 2000);
    }
    var timer = new Timer()
  }
}
</script>

<style scoped>
</style>
